package com.neighbor.neighborhooduser.service.impl;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.neighbor.neighborhooduser.pojo.ItemOrders;
import com.neighbor.neighborhooduser.dao.IItemOrdersDao;
import com.neighbor.neighborhooduser.pojo.OrderStatus;
import com.neighbor.neighborhooduser.pojo.OrderWithItemDTO;
import com.neighbor.neighborhooduser.service.IItemOrdersService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.io.Resources;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collection;
import java.util.List;

/**
 * <p>
 * 物品交易订单表 服务实现类
 * </p>
 *
 * @author song
 * @since 2025-09-22 09:13:04
 */
@Service
public class ItemOrdersServiceImpl extends ServiceImpl<IItemOrdersDao, ItemOrders> implements IItemOrdersService {
    @Autowired
    private IItemOrdersDao iItemOrdersDao;
    @Autowired
    private IItemOrdersDao itemOrdersDao;
    @Override
    public Integer createOrder(ItemOrders orders) {
        return iItemOrdersDao.createOrder(orders);
    }

    @Override
    public ItemOrders getByOrderNumber(String orderNumber) {
        return iItemOrdersDao.getByOrderNumber(orderNumber);
    }

    @Override
    public Integer updateStatus(Integer id) {
        return iItemOrdersDao.updateStatus(id);
    }
 // 卖家订单查询
    @Override
    public List<OrderWithItemDTO> findOrdersBySellerAndStatus(Integer sellerId, Byte status) {
        // 使用状态枚举增强可读性
        OrderStatus orderStatus = OrderStatus.fromValue(status);
        return iItemOrdersDao.findBySellerAndStatus(sellerId, orderStatus);
    }


    // 买家订单查询
    @Override
    public List<OrderWithItemDTO> findOrdersByBuyerAndStatus(Integer buyerId, Byte status) {
        // 使用状态枚举增强可读性
        OrderStatus orderStatus = OrderStatus.fromValue(status);
        return iItemOrdersDao.findByBuyerAndStatus(buyerId, orderStatus);
    }






    //模糊查询订单
    @Override
    public List<OrderWithItemDTO> findOrdersByUserIdAndItemTitle(Integer userId, String title) {
        // 添加通配符进行模糊匹配
        return itemOrdersDao.findByUserIdAndItemTitle(userId, "%" + title + "%");    }

    //两个都是获取作为卖家或者买家的订单
    @Override
    public List<OrderWithItemDTO> findSellerOrdersWithDetails(Integer sellerId) {
        return itemOrdersDao.findSellerOrdersWithDetails(sellerId);
    }

    @Override
    public List<OrderWithItemDTO> findBuyerOrdersWithDetails(Integer buyerId) {
        return itemOrdersDao.findBuyerOrdersWithDetails(buyerId);
    }

    @Override
    public OrderWithItemDTO findOrderDetailsById(Integer orderId) {
        return itemOrdersDao.findOrderDetailsById(orderId);
    }
}
